<?php
class lapkwitansi_model extends CI_Model
{
	// Call the module constructor
	function __construct(){
		parent::__construct();
	}
	
	function getkwitansipembelian($tgl,$tgl2)
	{
		if ($tgl != "" or $tgl2 !="")
		{
			$query = $this->db->query("SELECT * from kwitansi 
			where Active='1' and CreatedOn between '".$tgl."' and '".$tgl2."'");
		}else{
			$query = $this->db->query("SELECT * from kwitansi");
		}
		
		//var_dump($this->db->last_query());exit;
		
		return $query->result();
	}
	
	function getkwitansipenjualan($tgl,$tgl1)
	{
		if ($tgl != "" or $tgl1 !="")
		{
			$query = $this->db->query("select * from
										(
										SELECT nofaktur,totalamount,nokwitansi,a.createdon,namapelanggan,TotalQuantity,Typebayar,bk.bankname,Banknamepelanggan,NoRekeningpelanggan,Keterangan,a.CreatedBy from kwitansipenjualan A
left join master_bank bk on a.KodeBankpenerimaan = bk.kodebank
where a.Active='1' 
union all
select nofaktur,(-1 * totalamount_in),nokwitansi,createdon,'','','CASH','','','','','' from mutasi_cash
where Active='1' and nofaktur in (select nofaktur from kwitansipenjualan)
union all
select nofaktur,(-1 * totalamount_in),nokwitansi,mb.createdon,'','','BANK',bk.bankname,'','','','' from mutasi_bank mb left join master_bank bk on mb.kodebank = bk.kodebank
where mb.Active='1' and nofaktur in (select nofaktur from kwitansipenjualan)
union all
select nofaktur,(-1 * totalamount_in),nokwitansi,createdon,'','','GIRO','','','','','' from mutasi_giro
where Active='1' and nofaktur in (select nofaktur from kwitansipenjualan)
										) z
			where CreatedOn between '".$tgl."' and '".$tgl1."' order by nofaktur");
		}else{
			$query = $this->db->query("select * from
										(
										SELECT nofaktur,totalamount,nokwitansi,a.createdon,namapelanggan,TotalQuantity,Typebayar,bk.bankname,Banknamepelanggan,NoRekeningpelanggan,Keterangan,a.CreatedBy from kwitansipenjualan A
left join master_bank bk on a.KodeBankpenerimaan = bk.kodebank
where a.Active='1' 
union all
select nofaktur,(-1 * totalamount_in),nokwitansi,createdon,'','','CASH','','','','','' from mutasi_cash
where Active='1' and nofaktur in (select nofaktur from kwitansipenjualan)
union all
select nofaktur,(-1 * totalamount_in),nokwitansi,mb.createdon,'','','BANK',bk.bankname,'','','','' from mutasi_bank mb left join master_bank bk on mb.kodebank = bk.kodebank
where mb.Active='1' and nofaktur in (select nofaktur from kwitansipenjualan)
union all
select nofaktur,(-1 * totalamount_in),nokwitansi,createdon,'','','GIRO','','','','','' from mutasi_giro
where Active='1' and nofaktur in (select nofaktur from kwitansipenjualan)
										) z order by nofaktur");
		}
		
		//var_dump($this->db->last_query());exit;
		
		return $query->result();
		
		
	}
}
?>